package ru.example.mongotest2.service;

import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import ru.example.mongotest2.domain.Person;
import ru.example.mongotest2.repository.PersonRepository;

import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
public class PersonServiceImpl implements PersonService {

    private final PersonRepository repository;

    @Override
    public Optional<Person> findById(String id) {
        return repository.findById(id);
    }

    @Override
    public List<Person> getAll() {
        return repository.findAll();
    }

    @Override
    public void create(Person person) {
        repository.save(person);
    }

    @Override
    public List<Person> findByAge(int age) {
        return repository.findByAge(age);
    }

    @Override
    public void delete(String id) {
        repository.deleteById(id);
    }

    @Override
    public Person update(Person person) {
        return repository.save(person);
    }
}
